package com.taoym.voucher.admin.utils;

/**
 * @author: taoym
 * @date: 2020/8/8 12:41
 * @desc: threadLocal工具类
 */
public class AdminThreadLocalUtils {

    private final ThreadLocal<Integer> threadLocal = new ThreadLocal<>();

    //new一个实例
    private static final AdminThreadLocalUtils instance = new AdminThreadLocalUtils();

    //私有化构造
    private AdminThreadLocalUtils() {
    }

    //获取单例
    public static AdminThreadLocalUtils getInstance() {
        return instance;
    }


    public void bind(Integer userId) {
        threadLocal.set(userId);
    }

    public Integer get() {
        return threadLocal.get();
    }

    public void remove() {
        threadLocal.remove();
    }
}
